package qldc.pm.tiensu.service.persistence;

import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.CalendarUtil;
import com.liferay.portal.kernel.util.CharPool;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnmodifiableList;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import qldc.pm.tiensu.NoSuchLichSuXoaAnTichException;
import qldc.pm.tiensu.model.LichSuXoaAnTich;
import qldc.pm.tiensu.model.impl.LichSuXoaAnTichImpl;
import qldc.pm.tiensu.model.impl.LichSuXoaAnTichModelImpl;
import qldc.pm.tiensu.service.persistence.LichSuXoaAnTichPersistence;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * The persistence implementation for the lich su xoa an tich service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see LichSuXoaAnTichPersistence
 * @see LichSuXoaAnTichUtil
 * @generated
 */
public class LichSuXoaAnTichPersistenceImpl extends BasePersistenceImpl<LichSuXoaAnTich>
    implements LichSuXoaAnTichPersistence {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. Always use {@link LichSuXoaAnTichUtil} to access the lich su xoa an tich persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
     */
    public static final String FINDER_CLASS_NAME_ENTITY = LichSuXoaAnTichImpl.class.getName();
    public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List1";
    public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List2";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
            "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
    public static final FinderPath FINDER_PATH_FETCH_BY_TIENSUID = new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class, FINDER_CLASS_NAME_ENTITY,
            "fetchByTienSuId", new String[] { Long.class.getName() },
            LichSuXoaAnTichModelImpl.TIENSUID_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_TIENSUID = new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTienSuId",
            new String[] { Long.class.getName() });
    private static final String _FINDER_COLUMN_TIENSUID_TIENSUID_2 = "lichSuXoaAnTich.tienSuId = ?";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_HOTEN_MASOHOSO_NGAYLAPHOSO =
        new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
            "findByHoTen_MaSoHoSo_NgayLapHoSo",
            new String[] {
                String.class.getName(), String.class.getName(),
                Date.class.getName(),
                
            Integer.class.getName(), Integer.class.getName(),
                OrderByComparator.class.getName()
            });
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_HOTEN_MASOHOSO_NGAYLAPHOSO =
        new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
            "countByHoTen_MaSoHoSo_NgayLapHoSo",
            new String[] {
                String.class.getName(), String.class.getName(),
                Date.class.getName()
            });
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_1 =
        "lichSuXoaAnTich.hoVaTenDoiTuongTienSu LIKE NULL AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_2 =
        "lichSuXoaAnTich.hoVaTenDoiTuongTienSu LIKE ? AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_3 =
        "(lichSuXoaAnTich.hoVaTenDoiTuongTienSu IS NULL OR lichSuXoaAnTich.hoVaTenDoiTuongTienSu LIKE '') AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_1 =
        "lichSuXoaAnTich.maHoSoXoaAnTich LIKE NULL AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_2 =
        "lichSuXoaAnTich.maHoSoXoaAnTich LIKE ? AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_3 =
        "(lichSuXoaAnTich.maHoSoXoaAnTich IS NULL OR lichSuXoaAnTich.maHoSoXoaAnTich LIKE '') AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_1 =
        "lichSuXoaAnTich.ngayYeuCauXoaAnTich IS NULL";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_2 =
        "lichSuXoaAnTich.ngayYeuCauXoaAnTich = ?";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_HOTEN_MASOHOSO =
        new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
            "findByHoTen_MaSoHoSo",
            new String[] {
                String.class.getName(), String.class.getName(),
                
            Integer.class.getName(), Integer.class.getName(),
                OrderByComparator.class.getName()
            });
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_HOTEN_MASOHOSO =
        new FinderPath(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByHoTen_MaSoHoSo",
            new String[] { String.class.getName(), String.class.getName() });
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_1 =
        "lichSuXoaAnTich.hoVaTenDoiTuongTienSu LIKE NULL AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_2 =
        "lichSuXoaAnTich.hoVaTenDoiTuongTienSu LIKE ? AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_3 =
        "(lichSuXoaAnTich.hoVaTenDoiTuongTienSu IS NULL OR lichSuXoaAnTich.hoVaTenDoiTuongTienSu LIKE '') AND ";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_1 = "lichSuXoaAnTich.maHoSoXoaAnTich LIKE NULL";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_2 = "lichSuXoaAnTich.maHoSoXoaAnTich LIKE ?";
    private static final String _FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_3 = "(lichSuXoaAnTich.maHoSoXoaAnTich IS NULL OR lichSuXoaAnTich.maHoSoXoaAnTich LIKE '')";
    private static final String _SQL_SELECT_LICHSUXOAANTICH = "SELECT lichSuXoaAnTich FROM LichSuXoaAnTich lichSuXoaAnTich";
    private static final String _SQL_SELECT_LICHSUXOAANTICH_WHERE = "SELECT lichSuXoaAnTich FROM LichSuXoaAnTich lichSuXoaAnTich WHERE ";
    private static final String _SQL_COUNT_LICHSUXOAANTICH = "SELECT COUNT(lichSuXoaAnTich) FROM LichSuXoaAnTich lichSuXoaAnTich";
    private static final String _SQL_COUNT_LICHSUXOAANTICH_WHERE = "SELECT COUNT(lichSuXoaAnTich) FROM LichSuXoaAnTich lichSuXoaAnTich WHERE ";
    private static final String _ORDER_BY_ENTITY_ALIAS = "lichSuXoaAnTich.";
    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LichSuXoaAnTich exists with the primary key ";
    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LichSuXoaAnTich exists with the key {";
    private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
                PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
    private static Log _log = LogFactoryUtil.getLog(LichSuXoaAnTichPersistenceImpl.class);
    private static LichSuXoaAnTich _nullLichSuXoaAnTich = new LichSuXoaAnTichImpl() {
            @Override
            public Object clone() {
                return this;
            }

            @Override
            public CacheModel<LichSuXoaAnTich> toCacheModel() {
                return _nullLichSuXoaAnTichCacheModel;
            }
        };

    private static CacheModel<LichSuXoaAnTich> _nullLichSuXoaAnTichCacheModel = new CacheModel<LichSuXoaAnTich>() {
            @Override
            public LichSuXoaAnTich toEntityModel() {
                return _nullLichSuXoaAnTich;
            }
        };

    public LichSuXoaAnTichPersistenceImpl() {
        setModelClass(LichSuXoaAnTich.class);
    }

    /**
     * Returns the lich su xoa an tich where tienSuId = &#63; or throws a {@link qldc.pm.tiensu.NoSuchLichSuXoaAnTichException} if it could not be found.
     *
     * @param tienSuId the tien su ID
     * @return the matching lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich findByTienSuId(long tienSuId)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = fetchByTienSuId(tienSuId);

        if (lichSuXoaAnTich == null) {
            StringBundler msg = new StringBundler(4);

            msg.append(_NO_SUCH_ENTITY_WITH_KEY);

            msg.append("tienSuId=");
            msg.append(tienSuId);

            msg.append(StringPool.CLOSE_CURLY_BRACE);

            if (_log.isWarnEnabled()) {
                _log.warn(msg.toString());
            }

            throw new NoSuchLichSuXoaAnTichException(msg.toString());
        }

        return lichSuXoaAnTich;
    }

    /**
     * Returns the lich su xoa an tich where tienSuId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
     *
     * @param tienSuId the tien su ID
     * @return the matching lich su xoa an tich, or <code>null</code> if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByTienSuId(long tienSuId)
        throws SystemException {
        return fetchByTienSuId(tienSuId, true);
    }

    /**
     * Returns the lich su xoa an tich where tienSuId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
     *
     * @param tienSuId the tien su ID
     * @param retrieveFromCache whether to use the finder cache
     * @return the matching lich su xoa an tich, or <code>null</code> if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByTienSuId(long tienSuId,
        boolean retrieveFromCache) throws SystemException {
        Object[] finderArgs = new Object[] { tienSuId };

        Object result = null;

        if (retrieveFromCache) {
            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_TIENSUID,
                    finderArgs, this);
        }

        if (result instanceof LichSuXoaAnTich) {
            LichSuXoaAnTich lichSuXoaAnTich = (LichSuXoaAnTich) result;

            if ((tienSuId != lichSuXoaAnTich.getTienSuId())) {
                result = null;
            }
        }

        if (result == null) {
            StringBundler query = new StringBundler(3);

            query.append(_SQL_SELECT_LICHSUXOAANTICH_WHERE);

            query.append(_FINDER_COLUMN_TIENSUID_TIENSUID_2);

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(tienSuId);

                List<LichSuXoaAnTich> list = q.list();

                if (list.isEmpty()) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID,
                        finderArgs, list);
                } else {
                    if ((list.size() > 1) && _log.isWarnEnabled()) {
                        _log.warn(
                            "LichSuXoaAnTichPersistenceImpl.fetchByTienSuId(long, boolean) with parameters (" +
                            StringUtil.merge(finderArgs) +
                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                    }

                    LichSuXoaAnTich lichSuXoaAnTich = list.get(0);

                    result = lichSuXoaAnTich;

                    cacheResult(lichSuXoaAnTich);

                    if ((lichSuXoaAnTich.getTienSuId() != tienSuId)) {
                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID,
                            finderArgs, lichSuXoaAnTich);
                    }
                }
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TIENSUID,
                    finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        if (result instanceof List<?>) {
            return null;
        } else {
            return (LichSuXoaAnTich) result;
        }
    }

    /**
     * Removes the lich su xoa an tich where tienSuId = &#63; from the database.
     *
     * @param tienSuId the tien su ID
     * @return the lich su xoa an tich that was removed
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich removeByTienSuId(long tienSuId)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = findByTienSuId(tienSuId);

        return remove(lichSuXoaAnTich);
    }

    /**
     * Returns the number of lich su xoa an tichs where tienSuId = &#63;.
     *
     * @param tienSuId the tien su ID
     * @return the number of matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByTienSuId(long tienSuId) throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_TIENSUID;

        Object[] finderArgs = new Object[] { tienSuId };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_LICHSUXOAANTICH_WHERE);

            query.append(_FINDER_COLUMN_TIENSUID_TIENSUID_2);

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(tienSuId);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @return the matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findByHoTen_MaSoHoSo_NgayLapHoSo(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich) throws SystemException {
        return findByHoTen_MaSoHoSo_NgayLapHoSo(hoVaTenDoiTuongTienSu,
            maHoSoXoaAnTich, ngayYeuCauXoaAnTich, QueryUtil.ALL_POS,
            QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.LichSuXoaAnTichModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @param start the lower bound of the range of lich su xoa an tichs
     * @param end the upper bound of the range of lich su xoa an tichs (not inclusive)
     * @return the range of matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findByHoTen_MaSoHoSo_NgayLapHoSo(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich, int start, int end) throws SystemException {
        return findByHoTen_MaSoHoSo_NgayLapHoSo(hoVaTenDoiTuongTienSu,
            maHoSoXoaAnTich, ngayYeuCauXoaAnTich, start, end, null);
    }

    /**
     * Returns an ordered range of all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.LichSuXoaAnTichModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @param start the lower bound of the range of lich su xoa an tichs
     * @param end the upper bound of the range of lich su xoa an tichs (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findByHoTen_MaSoHoSo_NgayLapHoSo(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_HOTEN_MASOHOSO_NGAYLAPHOSO;
        finderArgs = new Object[] {
                hoVaTenDoiTuongTienSu, maHoSoXoaAnTich, ngayYeuCauXoaAnTich,
                
                start, end, orderByComparator
            };

        List<LichSuXoaAnTich> list = (List<LichSuXoaAnTich>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (LichSuXoaAnTich lichSuXoaAnTich : list) {
                if (!StringUtil.wildcardMatches(
                            lichSuXoaAnTich.getHoVaTenDoiTuongTienSu(),
                            hoVaTenDoiTuongTienSu, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true) ||
                        !StringUtil.wildcardMatches(
                            lichSuXoaAnTich.getMaHoSoXoaAnTich(),
                            maHoSoXoaAnTich, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true) ||
                        !Validator.equals(ngayYeuCauXoaAnTich,
                            lichSuXoaAnTich.getNgayYeuCauXoaAnTich())) {
                    list = null;

                    break;
                }
            }
        }

        if (list == null) {
            StringBundler query = null;

            if (orderByComparator != null) {
                query = new StringBundler(5 +
                        (orderByComparator.getOrderByFields().length * 3));
            } else {
                query = new StringBundler(5);
            }

            query.append(_SQL_SELECT_LICHSUXOAANTICH_WHERE);

            boolean bindHoVaTenDoiTuongTienSu = false;

            if (hoVaTenDoiTuongTienSu == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_1);
            } else if (hoVaTenDoiTuongTienSu.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_3);
            } else {
                bindHoVaTenDoiTuongTienSu = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_2);
            }

            boolean bindMaHoSoXoaAnTich = false;

            if (maHoSoXoaAnTich == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_1);
            } else if (maHoSoXoaAnTich.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_3);
            } else {
                bindMaHoSoXoaAnTich = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_2);
            }

            boolean bindNgayYeuCauXoaAnTich = false;

            if (ngayYeuCauXoaAnTich == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_1);
            } else {
                bindNgayYeuCauXoaAnTich = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_2);
            }

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);
            } else
             if (pagination) {
                query.append(LichSuXoaAnTichModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindHoVaTenDoiTuongTienSu) {
                    qPos.add(hoVaTenDoiTuongTienSu);
                }

                if (bindMaHoSoXoaAnTich) {
                    qPos.add(maHoSoXoaAnTich);
                }

                if (bindNgayYeuCauXoaAnTich) {
                    qPos.add(CalendarUtil.getTimestamp(ngayYeuCauXoaAnTich));
                }

                if (!pagination) {
                    list = (List<LichSuXoaAnTich>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<LichSuXoaAnTich>(list);
                } else {
                    list = (List<LichSuXoaAnTich>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich findByHoTen_MaSoHoSo_NgayLapHoSo_First(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich, OrderByComparator orderByComparator)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = fetchByHoTen_MaSoHoSo_NgayLapHoSo_First(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, ngayYeuCauXoaAnTich, orderByComparator);

        if (lichSuXoaAnTich != null) {
            return lichSuXoaAnTich;
        }

        StringBundler msg = new StringBundler(8);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("hoVaTenDoiTuongTienSu=");
        msg.append(hoVaTenDoiTuongTienSu);

        msg.append(", maHoSoXoaAnTich=");
        msg.append(maHoSoXoaAnTich);

        msg.append(", ngayYeuCauXoaAnTich=");
        msg.append(ngayYeuCauXoaAnTich);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchLichSuXoaAnTichException(msg.toString());
    }

    /**
     * Returns the first lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching lich su xoa an tich, or <code>null</code> if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByHoTen_MaSoHoSo_NgayLapHoSo_First(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich, OrderByComparator orderByComparator)
        throws SystemException {
        List<LichSuXoaAnTich> list = findByHoTen_MaSoHoSo_NgayLapHoSo(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, ngayYeuCauXoaAnTich, 0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich findByHoTen_MaSoHoSo_NgayLapHoSo_Last(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich, OrderByComparator orderByComparator)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = fetchByHoTen_MaSoHoSo_NgayLapHoSo_Last(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, ngayYeuCauXoaAnTich, orderByComparator);

        if (lichSuXoaAnTich != null) {
            return lichSuXoaAnTich;
        }

        StringBundler msg = new StringBundler(8);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("hoVaTenDoiTuongTienSu=");
        msg.append(hoVaTenDoiTuongTienSu);

        msg.append(", maHoSoXoaAnTich=");
        msg.append(maHoSoXoaAnTich);

        msg.append(", ngayYeuCauXoaAnTich=");
        msg.append(ngayYeuCauXoaAnTich);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchLichSuXoaAnTichException(msg.toString());
    }

    /**
     * Returns the last lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching lich su xoa an tich, or <code>null</code> if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByHoTen_MaSoHoSo_NgayLapHoSo_Last(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich, OrderByComparator orderByComparator)
        throws SystemException {
        int count = countByHoTen_MaSoHoSo_NgayLapHoSo(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, ngayYeuCauXoaAnTich);

        if (count == 0) {
            return null;
        }

        List<LichSuXoaAnTich> list = findByHoTen_MaSoHoSo_NgayLapHoSo(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, ngayYeuCauXoaAnTich, count - 1, count,
                orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the lich su xoa an tichs before and after the current lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * @param lichSuXoaAnTichId the primary key of the current lich su xoa an tich
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich[] findByHoTen_MaSoHoSo_NgayLapHoSo_PrevAndNext(
        long lichSuXoaAnTichId, String hoVaTenDoiTuongTienSu,
        String maHoSoXoaAnTich, Date ngayYeuCauXoaAnTich,
        OrderByComparator orderByComparator)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = findByPrimaryKey(lichSuXoaAnTichId);

        Session session = null;

        try {
            session = openSession();

            LichSuXoaAnTich[] array = new LichSuXoaAnTichImpl[3];

            array[0] = getByHoTen_MaSoHoSo_NgayLapHoSo_PrevAndNext(session,
                    lichSuXoaAnTich, hoVaTenDoiTuongTienSu, maHoSoXoaAnTich,
                    ngayYeuCauXoaAnTich, orderByComparator, true);

            array[1] = lichSuXoaAnTich;

            array[2] = getByHoTen_MaSoHoSo_NgayLapHoSo_PrevAndNext(session,
                    lichSuXoaAnTich, hoVaTenDoiTuongTienSu, maHoSoXoaAnTich,
                    ngayYeuCauXoaAnTich, orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected LichSuXoaAnTich getByHoTen_MaSoHoSo_NgayLapHoSo_PrevAndNext(
        Session session, LichSuXoaAnTich lichSuXoaAnTich,
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich, OrderByComparator orderByComparator,
        boolean previous) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(6 +
                    (orderByComparator.getOrderByFields().length * 6));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_LICHSUXOAANTICH_WHERE);

        boolean bindHoVaTenDoiTuongTienSu = false;

        if (hoVaTenDoiTuongTienSu == null) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_1);
        } else if (hoVaTenDoiTuongTienSu.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_3);
        } else {
            bindHoVaTenDoiTuongTienSu = true;

            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_2);
        }

        boolean bindMaHoSoXoaAnTich = false;

        if (maHoSoXoaAnTich == null) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_1);
        } else if (maHoSoXoaAnTich.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_3);
        } else {
            bindMaHoSoXoaAnTich = true;

            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_2);
        }

        boolean bindNgayYeuCauXoaAnTich = false;

        if (ngayYeuCauXoaAnTich == null) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_1);
        } else {
            bindNgayYeuCauXoaAnTich = true;

            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_2);
        }

        if (orderByComparator != null) {
            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

            if (orderByConditionFields.length > 0) {
                query.append(WHERE_AND);
            }

            for (int i = 0; i < orderByConditionFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByConditionFields[i]);

                if ((i + 1) < orderByConditionFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
                    } else {
                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN);
                    } else {
                        query.append(WHERE_LESSER_THAN);
                    }
                }
            }

            query.append(ORDER_BY_CLAUSE);

            String[] orderByFields = orderByComparator.getOrderByFields();

            for (int i = 0; i < orderByFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByFields[i]);

                if ((i + 1) < orderByFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC_HAS_NEXT);
                    } else {
                        query.append(ORDER_BY_DESC_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC);
                    } else {
                        query.append(ORDER_BY_DESC);
                    }
                }
            }
        } else {
            query.append(LichSuXoaAnTichModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

        q.setFirstResult(0);
        q.setMaxResults(2);

        QueryPos qPos = QueryPos.getInstance(q);

        if (bindHoVaTenDoiTuongTienSu) {
            qPos.add(hoVaTenDoiTuongTienSu);
        }

        if (bindMaHoSoXoaAnTich) {
            qPos.add(maHoSoXoaAnTich);
        }

        if (bindNgayYeuCauXoaAnTich) {
            qPos.add(CalendarUtil.getTimestamp(ngayYeuCauXoaAnTich));
        }

        if (orderByComparator != null) {
            Object[] values = orderByComparator.getOrderByConditionValues(lichSuXoaAnTich);

            for (Object value : values) {
                qPos.add(value);
            }
        }

        List<LichSuXoaAnTich> list = q.list();

        if (list.size() == 2) {
            return list.get(1);
        } else {
            return null;
        }
    }

    /**
     * Removes all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63; from the database.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeByHoTen_MaSoHoSo_NgayLapHoSo(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        Date ngayYeuCauXoaAnTich) throws SystemException {
        for (LichSuXoaAnTich lichSuXoaAnTich : findByHoTen_MaSoHoSo_NgayLapHoSo(
                hoVaTenDoiTuongTienSu, maHoSoXoaAnTich, ngayYeuCauXoaAnTich,
                QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
            remove(lichSuXoaAnTich);
        }
    }

    /**
     * Returns the number of lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; and ngayYeuCauXoaAnTich = &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param ngayYeuCauXoaAnTich the ngay yeu cau xoa an tich
     * @return the number of matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByHoTen_MaSoHoSo_NgayLapHoSo(String hoVaTenDoiTuongTienSu,
        String maHoSoXoaAnTich, Date ngayYeuCauXoaAnTich)
        throws SystemException {
        FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_HOTEN_MASOHOSO_NGAYLAPHOSO;

        Object[] finderArgs = new Object[] {
                hoVaTenDoiTuongTienSu, maHoSoXoaAnTich, ngayYeuCauXoaAnTich
            };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(4);

            query.append(_SQL_COUNT_LICHSUXOAANTICH_WHERE);

            boolean bindHoVaTenDoiTuongTienSu = false;

            if (hoVaTenDoiTuongTienSu == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_1);
            } else if (hoVaTenDoiTuongTienSu.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_3);
            } else {
                bindHoVaTenDoiTuongTienSu = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_HOVATENDOITUONGTIENSU_2);
            }

            boolean bindMaHoSoXoaAnTich = false;

            if (maHoSoXoaAnTich == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_1);
            } else if (maHoSoXoaAnTich.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_3);
            } else {
                bindMaHoSoXoaAnTich = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_MAHOSOXOAANTICH_2);
            }

            boolean bindNgayYeuCauXoaAnTich = false;

            if (ngayYeuCauXoaAnTich == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_1);
            } else {
                bindNgayYeuCauXoaAnTich = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_NGAYLAPHOSO_NGAYYEUCAUXOAANTICH_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindHoVaTenDoiTuongTienSu) {
                    qPos.add(hoVaTenDoiTuongTienSu);
                }

                if (bindMaHoSoXoaAnTich) {
                    qPos.add(maHoSoXoaAnTich);
                }

                if (bindNgayYeuCauXoaAnTich) {
                    qPos.add(CalendarUtil.getTimestamp(ngayYeuCauXoaAnTich));
                }

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @return the matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findByHoTen_MaSoHoSo(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich)
        throws SystemException {
        return findByHoTen_MaSoHoSo(hoVaTenDoiTuongTienSu, maHoSoXoaAnTich,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.LichSuXoaAnTichModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param start the lower bound of the range of lich su xoa an tichs
     * @param end the upper bound of the range of lich su xoa an tichs (not inclusive)
     * @return the range of matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findByHoTen_MaSoHoSo(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich, int start, int end)
        throws SystemException {
        return findByHoTen_MaSoHoSo(hoVaTenDoiTuongTienSu, maHoSoXoaAnTich,
            start, end, null);
    }

    /**
     * Returns an ordered range of all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.LichSuXoaAnTichModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param start the lower bound of the range of lich su xoa an tichs
     * @param end the upper bound of the range of lich su xoa an tichs (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findByHoTen_MaSoHoSo(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich, int start,
        int end, OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_HOTEN_MASOHOSO;
        finderArgs = new Object[] {
                hoVaTenDoiTuongTienSu, maHoSoXoaAnTich,
                
                start, end, orderByComparator
            };

        List<LichSuXoaAnTich> list = (List<LichSuXoaAnTich>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (LichSuXoaAnTich lichSuXoaAnTich : list) {
                if (!StringUtil.wildcardMatches(
                            lichSuXoaAnTich.getHoVaTenDoiTuongTienSu(),
                            hoVaTenDoiTuongTienSu, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true) ||
                        !StringUtil.wildcardMatches(
                            lichSuXoaAnTich.getMaHoSoXoaAnTich(),
                            maHoSoXoaAnTich, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true)) {
                    list = null;

                    break;
                }
            }
        }

        if (list == null) {
            StringBundler query = null;

            if (orderByComparator != null) {
                query = new StringBundler(4 +
                        (orderByComparator.getOrderByFields().length * 3));
            } else {
                query = new StringBundler(4);
            }

            query.append(_SQL_SELECT_LICHSUXOAANTICH_WHERE);

            boolean bindHoVaTenDoiTuongTienSu = false;

            if (hoVaTenDoiTuongTienSu == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_1);
            } else if (hoVaTenDoiTuongTienSu.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_3);
            } else {
                bindHoVaTenDoiTuongTienSu = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_2);
            }

            boolean bindMaHoSoXoaAnTich = false;

            if (maHoSoXoaAnTich == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_1);
            } else if (maHoSoXoaAnTich.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_3);
            } else {
                bindMaHoSoXoaAnTich = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_2);
            }

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);
            } else
             if (pagination) {
                query.append(LichSuXoaAnTichModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindHoVaTenDoiTuongTienSu) {
                    qPos.add(hoVaTenDoiTuongTienSu);
                }

                if (bindMaHoSoXoaAnTich) {
                    qPos.add(maHoSoXoaAnTich);
                }

                if (!pagination) {
                    list = (List<LichSuXoaAnTich>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<LichSuXoaAnTich>(list);
                } else {
                    list = (List<LichSuXoaAnTich>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich findByHoTen_MaSoHoSo_First(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        OrderByComparator orderByComparator)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = fetchByHoTen_MaSoHoSo_First(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, orderByComparator);

        if (lichSuXoaAnTich != null) {
            return lichSuXoaAnTich;
        }

        StringBundler msg = new StringBundler(6);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("hoVaTenDoiTuongTienSu=");
        msg.append(hoVaTenDoiTuongTienSu);

        msg.append(", maHoSoXoaAnTich=");
        msg.append(maHoSoXoaAnTich);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchLichSuXoaAnTichException(msg.toString());
    }

    /**
     * Returns the first lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching lich su xoa an tich, or <code>null</code> if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByHoTen_MaSoHoSo_First(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        OrderByComparator orderByComparator) throws SystemException {
        List<LichSuXoaAnTich> list = findByHoTen_MaSoHoSo(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, 0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich findByHoTen_MaSoHoSo_Last(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        OrderByComparator orderByComparator)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = fetchByHoTen_MaSoHoSo_Last(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, orderByComparator);

        if (lichSuXoaAnTich != null) {
            return lichSuXoaAnTich;
        }

        StringBundler msg = new StringBundler(6);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("hoVaTenDoiTuongTienSu=");
        msg.append(hoVaTenDoiTuongTienSu);

        msg.append(", maHoSoXoaAnTich=");
        msg.append(maHoSoXoaAnTich);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchLichSuXoaAnTichException(msg.toString());
    }

    /**
     * Returns the last lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching lich su xoa an tich, or <code>null</code> if a matching lich su xoa an tich could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByHoTen_MaSoHoSo_Last(
        String hoVaTenDoiTuongTienSu, String maHoSoXoaAnTich,
        OrderByComparator orderByComparator) throws SystemException {
        int count = countByHoTen_MaSoHoSo(hoVaTenDoiTuongTienSu, maHoSoXoaAnTich);

        if (count == 0) {
            return null;
        }

        List<LichSuXoaAnTich> list = findByHoTen_MaSoHoSo(hoVaTenDoiTuongTienSu,
                maHoSoXoaAnTich, count - 1, count, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the lich su xoa an tichs before and after the current lich su xoa an tich in the ordered set where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * @param lichSuXoaAnTichId the primary key of the current lich su xoa an tich
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich[] findByHoTen_MaSoHoSo_PrevAndNext(
        long lichSuXoaAnTichId, String hoVaTenDoiTuongTienSu,
        String maHoSoXoaAnTich, OrderByComparator orderByComparator)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = findByPrimaryKey(lichSuXoaAnTichId);

        Session session = null;

        try {
            session = openSession();

            LichSuXoaAnTich[] array = new LichSuXoaAnTichImpl[3];

            array[0] = getByHoTen_MaSoHoSo_PrevAndNext(session,
                    lichSuXoaAnTich, hoVaTenDoiTuongTienSu, maHoSoXoaAnTich,
                    orderByComparator, true);

            array[1] = lichSuXoaAnTich;

            array[2] = getByHoTen_MaSoHoSo_PrevAndNext(session,
                    lichSuXoaAnTich, hoVaTenDoiTuongTienSu, maHoSoXoaAnTich,
                    orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected LichSuXoaAnTich getByHoTen_MaSoHoSo_PrevAndNext(Session session,
        LichSuXoaAnTich lichSuXoaAnTich, String hoVaTenDoiTuongTienSu,
        String maHoSoXoaAnTich, OrderByComparator orderByComparator,
        boolean previous) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(6 +
                    (orderByComparator.getOrderByFields().length * 6));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_LICHSUXOAANTICH_WHERE);

        boolean bindHoVaTenDoiTuongTienSu = false;

        if (hoVaTenDoiTuongTienSu == null) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_1);
        } else if (hoVaTenDoiTuongTienSu.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_3);
        } else {
            bindHoVaTenDoiTuongTienSu = true;

            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_2);
        }

        boolean bindMaHoSoXoaAnTich = false;

        if (maHoSoXoaAnTich == null) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_1);
        } else if (maHoSoXoaAnTich.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_3);
        } else {
            bindMaHoSoXoaAnTich = true;

            query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_2);
        }

        if (orderByComparator != null) {
            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

            if (orderByConditionFields.length > 0) {
                query.append(WHERE_AND);
            }

            for (int i = 0; i < orderByConditionFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByConditionFields[i]);

                if ((i + 1) < orderByConditionFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
                    } else {
                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN);
                    } else {
                        query.append(WHERE_LESSER_THAN);
                    }
                }
            }

            query.append(ORDER_BY_CLAUSE);

            String[] orderByFields = orderByComparator.getOrderByFields();

            for (int i = 0; i < orderByFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByFields[i]);

                if ((i + 1) < orderByFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC_HAS_NEXT);
                    } else {
                        query.append(ORDER_BY_DESC_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC);
                    } else {
                        query.append(ORDER_BY_DESC);
                    }
                }
            }
        } else {
            query.append(LichSuXoaAnTichModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

        q.setFirstResult(0);
        q.setMaxResults(2);

        QueryPos qPos = QueryPos.getInstance(q);

        if (bindHoVaTenDoiTuongTienSu) {
            qPos.add(hoVaTenDoiTuongTienSu);
        }

        if (bindMaHoSoXoaAnTich) {
            qPos.add(maHoSoXoaAnTich);
        }

        if (orderByComparator != null) {
            Object[] values = orderByComparator.getOrderByConditionValues(lichSuXoaAnTich);

            for (Object value : values) {
                qPos.add(value);
            }
        }

        List<LichSuXoaAnTich> list = q.list();

        if (list.size() == 2) {
            return list.get(1);
        } else {
            return null;
        }
    }

    /**
     * Removes all the lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63; from the database.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeByHoTen_MaSoHoSo(String hoVaTenDoiTuongTienSu,
        String maHoSoXoaAnTich) throws SystemException {
        for (LichSuXoaAnTich lichSuXoaAnTich : findByHoTen_MaSoHoSo(
                hoVaTenDoiTuongTienSu, maHoSoXoaAnTich, QueryUtil.ALL_POS,
                QueryUtil.ALL_POS, null)) {
            remove(lichSuXoaAnTich);
        }
    }

    /**
     * Returns the number of lich su xoa an tichs where hoVaTenDoiTuongTienSu LIKE &#63; and maHoSoXoaAnTich LIKE &#63;.
     *
     * @param hoVaTenDoiTuongTienSu the ho va ten doi tuong tien su
     * @param maHoSoXoaAnTich the ma ho so xoa an tich
     * @return the number of matching lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByHoTen_MaSoHoSo(String hoVaTenDoiTuongTienSu,
        String maHoSoXoaAnTich) throws SystemException {
        FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_HOTEN_MASOHOSO;

        Object[] finderArgs = new Object[] {
                hoVaTenDoiTuongTienSu, maHoSoXoaAnTich
            };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(3);

            query.append(_SQL_COUNT_LICHSUXOAANTICH_WHERE);

            boolean bindHoVaTenDoiTuongTienSu = false;

            if (hoVaTenDoiTuongTienSu == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_1);
            } else if (hoVaTenDoiTuongTienSu.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_3);
            } else {
                bindHoVaTenDoiTuongTienSu = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_HOVATENDOITUONGTIENSU_2);
            }

            boolean bindMaHoSoXoaAnTich = false;

            if (maHoSoXoaAnTich == null) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_1);
            } else if (maHoSoXoaAnTich.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_3);
            } else {
                bindMaHoSoXoaAnTich = true;

                query.append(_FINDER_COLUMN_HOTEN_MASOHOSO_MAHOSOXOAANTICH_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindHoVaTenDoiTuongTienSu) {
                    qPos.add(hoVaTenDoiTuongTienSu);
                }

                if (bindMaHoSoXoaAnTich) {
                    qPos.add(maHoSoXoaAnTich);
                }

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Caches the lich su xoa an tich in the entity cache if it is enabled.
     *
     * @param lichSuXoaAnTich the lich su xoa an tich
     */
    @Override
    public void cacheResult(LichSuXoaAnTich lichSuXoaAnTich) {
        EntityCacheUtil.putResult(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class, lichSuXoaAnTich.getPrimaryKey(),
            lichSuXoaAnTich);

        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID,
            new Object[] { lichSuXoaAnTich.getTienSuId() }, lichSuXoaAnTich);

        lichSuXoaAnTich.resetOriginalValues();
    }

    /**
     * Caches the lich su xoa an tichs in the entity cache if it is enabled.
     *
     * @param lichSuXoaAnTichs the lich su xoa an tichs
     */
    @Override
    public void cacheResult(List<LichSuXoaAnTich> lichSuXoaAnTichs) {
        for (LichSuXoaAnTich lichSuXoaAnTich : lichSuXoaAnTichs) {
            if (EntityCacheUtil.getResult(
                        LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
                        LichSuXoaAnTichImpl.class,
                        lichSuXoaAnTich.getPrimaryKey()) == null) {
                cacheResult(lichSuXoaAnTich);
            } else {
                lichSuXoaAnTich.resetOriginalValues();
            }
        }
    }

    /**
     * Clears the cache for all lich su xoa an tichs.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache() {
        if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
            CacheRegistryUtil.clear(LichSuXoaAnTichImpl.class.getName());
        }

        EntityCacheUtil.clearCache(LichSuXoaAnTichImpl.class.getName());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    /**
     * Clears the cache for the lich su xoa an tich.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache(LichSuXoaAnTich lichSuXoaAnTich) {
        EntityCacheUtil.removeResult(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class, lichSuXoaAnTich.getPrimaryKey());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        clearUniqueFindersCache(lichSuXoaAnTich);
    }

    @Override
    public void clearCache(List<LichSuXoaAnTich> lichSuXoaAnTichs) {
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        for (LichSuXoaAnTich lichSuXoaAnTich : lichSuXoaAnTichs) {
            EntityCacheUtil.removeResult(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
                LichSuXoaAnTichImpl.class, lichSuXoaAnTich.getPrimaryKey());

            clearUniqueFindersCache(lichSuXoaAnTich);
        }
    }

    protected void cacheUniqueFindersCache(LichSuXoaAnTich lichSuXoaAnTich) {
        if (lichSuXoaAnTich.isNew()) {
            Object[] args = new Object[] { lichSuXoaAnTich.getTienSuId() };

            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TIENSUID, args,
                Long.valueOf(1));
            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID, args,
                lichSuXoaAnTich);
        } else {
            LichSuXoaAnTichModelImpl lichSuXoaAnTichModelImpl = (LichSuXoaAnTichModelImpl) lichSuXoaAnTich;

            if ((lichSuXoaAnTichModelImpl.getColumnBitmask() &
                    FINDER_PATH_FETCH_BY_TIENSUID.getColumnBitmask()) != 0) {
                Object[] args = new Object[] { lichSuXoaAnTich.getTienSuId() };

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TIENSUID, args,
                    Long.valueOf(1));
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID, args,
                    lichSuXoaAnTich);
            }
        }
    }

    protected void clearUniqueFindersCache(LichSuXoaAnTich lichSuXoaAnTich) {
        LichSuXoaAnTichModelImpl lichSuXoaAnTichModelImpl = (LichSuXoaAnTichModelImpl) lichSuXoaAnTich;

        Object[] args = new Object[] { lichSuXoaAnTich.getTienSuId() };

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TIENSUID, args);
        FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TIENSUID, args);

        if ((lichSuXoaAnTichModelImpl.getColumnBitmask() &
                FINDER_PATH_FETCH_BY_TIENSUID.getColumnBitmask()) != 0) {
            args = new Object[] { lichSuXoaAnTichModelImpl.getOriginalTienSuId() };

            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TIENSUID, args);
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TIENSUID, args);
        }
    }

    /**
     * Creates a new lich su xoa an tich with the primary key. Does not add the lich su xoa an tich to the database.
     *
     * @param lichSuXoaAnTichId the primary key for the new lich su xoa an tich
     * @return the new lich su xoa an tich
     */
    @Override
    public LichSuXoaAnTich create(long lichSuXoaAnTichId) {
        LichSuXoaAnTich lichSuXoaAnTich = new LichSuXoaAnTichImpl();

        lichSuXoaAnTich.setNew(true);
        lichSuXoaAnTich.setPrimaryKey(lichSuXoaAnTichId);

        return lichSuXoaAnTich;
    }

    /**
     * Removes the lich su xoa an tich with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param lichSuXoaAnTichId the primary key of the lich su xoa an tich
     * @return the lich su xoa an tich that was removed
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich remove(long lichSuXoaAnTichId)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        return remove((Serializable) lichSuXoaAnTichId);
    }

    /**
     * Removes the lich su xoa an tich with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param primaryKey the primary key of the lich su xoa an tich
     * @return the lich su xoa an tich that was removed
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich remove(Serializable primaryKey)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        Session session = null;

        try {
            session = openSession();

            LichSuXoaAnTich lichSuXoaAnTich = (LichSuXoaAnTich) session.get(LichSuXoaAnTichImpl.class,
                    primaryKey);

            if (lichSuXoaAnTich == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
                }

                throw new NoSuchLichSuXoaAnTichException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                    primaryKey);
            }

            return remove(lichSuXoaAnTich);
        } catch (NoSuchLichSuXoaAnTichException nsee) {
            throw nsee;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    @Override
    protected LichSuXoaAnTich removeImpl(LichSuXoaAnTich lichSuXoaAnTich)
        throws SystemException {
        lichSuXoaAnTich = toUnwrappedModel(lichSuXoaAnTich);

        Session session = null;

        try {
            session = openSession();

            if (!session.contains(lichSuXoaAnTich)) {
                lichSuXoaAnTich = (LichSuXoaAnTich) session.get(LichSuXoaAnTichImpl.class,
                        lichSuXoaAnTich.getPrimaryKeyObj());
            }

            if (lichSuXoaAnTich != null) {
                session.delete(lichSuXoaAnTich);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        if (lichSuXoaAnTich != null) {
            clearCache(lichSuXoaAnTich);
        }

        return lichSuXoaAnTich;
    }

    @Override
    public LichSuXoaAnTich updateImpl(
        qldc.pm.tiensu.model.LichSuXoaAnTich lichSuXoaAnTich)
        throws SystemException {
        lichSuXoaAnTich = toUnwrappedModel(lichSuXoaAnTich);

        boolean isNew = lichSuXoaAnTich.isNew();

        Session session = null;

        try {
            session = openSession();

            if (lichSuXoaAnTich.isNew()) {
                session.save(lichSuXoaAnTich);

                lichSuXoaAnTich.setNew(false);
            } else {
                session.merge(lichSuXoaAnTich);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

        if (isNew || !LichSuXoaAnTichModelImpl.COLUMN_BITMASK_ENABLED) {
            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
        }

        EntityCacheUtil.putResult(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
            LichSuXoaAnTichImpl.class, lichSuXoaAnTich.getPrimaryKey(),
            lichSuXoaAnTich);

        clearUniqueFindersCache(lichSuXoaAnTich);
        cacheUniqueFindersCache(lichSuXoaAnTich);

        return lichSuXoaAnTich;
    }

    protected LichSuXoaAnTich toUnwrappedModel(LichSuXoaAnTich lichSuXoaAnTich) {
        if (lichSuXoaAnTich instanceof LichSuXoaAnTichImpl) {
            return lichSuXoaAnTich;
        }

        LichSuXoaAnTichImpl lichSuXoaAnTichImpl = new LichSuXoaAnTichImpl();

        lichSuXoaAnTichImpl.setNew(lichSuXoaAnTich.isNew());
        lichSuXoaAnTichImpl.setPrimaryKey(lichSuXoaAnTich.getPrimaryKey());

        lichSuXoaAnTichImpl.setLichSuXoaAnTichId(lichSuXoaAnTich.getLichSuXoaAnTichId());
        lichSuXoaAnTichImpl.setTienSuId(lichSuXoaAnTich.getTienSuId());
        lichSuXoaAnTichImpl.setNguoiLapHoSoXoaAnTichId(lichSuXoaAnTich.getNguoiLapHoSoXoaAnTichId());
        lichSuXoaAnTichImpl.setNgayLapHoSoXoaAnTich(lichSuXoaAnTich.getNgayLapHoSoXoaAnTich());
        lichSuXoaAnTichImpl.setNguoiYeuCauXoaAnTich(lichSuXoaAnTich.getNguoiYeuCauXoaAnTich());
        lichSuXoaAnTichImpl.setNgayYeuCauXoaAnTich(lichSuXoaAnTich.getNgayYeuCauXoaAnTich());
        lichSuXoaAnTichImpl.setNguoiThucHienXoaAnTichTrongDuLieuID(lichSuXoaAnTich.getNguoiThucHienXoaAnTichTrongDuLieuID());
        lichSuXoaAnTichImpl.setNgayKyDuyetXoaAnTich(lichSuXoaAnTich.getNgayKyDuyetXoaAnTich());
        lichSuXoaAnTichImpl.setMaHoSoXoaAnTich(lichSuXoaAnTich.getMaHoSoXoaAnTich());
        lichSuXoaAnTichImpl.setChuThich(lichSuXoaAnTich.getChuThich());
        lichSuXoaAnTichImpl.setKinhGui(lichSuXoaAnTich.getKinhGui());
        lichSuXoaAnTichImpl.setHinhPhat(lichSuXoaAnTich.getHinhPhat());
        lichSuXoaAnTichImpl.setCoQuanThiHanhAn(lichSuXoaAnTich.getCoQuanThiHanhAn());
        lichSuXoaAnTichImpl.setSoQuyetDinhThiHanhAn(lichSuXoaAnTich.getSoQuyetDinhThiHanhAn());
        lichSuXoaAnTichImpl.setNgayQuyetDinhThiHanhAn(lichSuXoaAnTich.getNgayQuyetDinhThiHanhAn());
        lichSuXoaAnTichImpl.setHoVaTenDoiTuongTienSu(lichSuXoaAnTich.getHoVaTenDoiTuongTienSu());

        return lichSuXoaAnTichImpl;
    }

    /**
     * Returns the lich su xoa an tich with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
     *
     * @param primaryKey the primary key of the lich su xoa an tich
     * @return the lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich findByPrimaryKey(Serializable primaryKey)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = fetchByPrimaryKey(primaryKey);

        if (lichSuXoaAnTich == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }

            throw new NoSuchLichSuXoaAnTichException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                primaryKey);
        }

        return lichSuXoaAnTich;
    }

    /**
     * Returns the lich su xoa an tich with the primary key or throws a {@link qldc.pm.tiensu.NoSuchLichSuXoaAnTichException} if it could not be found.
     *
     * @param lichSuXoaAnTichId the primary key of the lich su xoa an tich
     * @return the lich su xoa an tich
     * @throws qldc.pm.tiensu.NoSuchLichSuXoaAnTichException if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich findByPrimaryKey(long lichSuXoaAnTichId)
        throws NoSuchLichSuXoaAnTichException, SystemException {
        return findByPrimaryKey((Serializable) lichSuXoaAnTichId);
    }

    /**
     * Returns the lich su xoa an tich with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param primaryKey the primary key of the lich su xoa an tich
     * @return the lich su xoa an tich, or <code>null</code> if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByPrimaryKey(Serializable primaryKey)
        throws SystemException {
        LichSuXoaAnTich lichSuXoaAnTich = (LichSuXoaAnTich) EntityCacheUtil.getResult(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
                LichSuXoaAnTichImpl.class, primaryKey);

        if (lichSuXoaAnTich == _nullLichSuXoaAnTich) {
            return null;
        }

        if (lichSuXoaAnTich == null) {
            Session session = null;

            try {
                session = openSession();

                lichSuXoaAnTich = (LichSuXoaAnTich) session.get(LichSuXoaAnTichImpl.class,
                        primaryKey);

                if (lichSuXoaAnTich != null) {
                    cacheResult(lichSuXoaAnTich);
                } else {
                    EntityCacheUtil.putResult(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
                        LichSuXoaAnTichImpl.class, primaryKey,
                        _nullLichSuXoaAnTich);
                }
            } catch (Exception e) {
                EntityCacheUtil.removeResult(LichSuXoaAnTichModelImpl.ENTITY_CACHE_ENABLED,
                    LichSuXoaAnTichImpl.class, primaryKey);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return lichSuXoaAnTich;
    }

    /**
     * Returns the lich su xoa an tich with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param lichSuXoaAnTichId the primary key of the lich su xoa an tich
     * @return the lich su xoa an tich, or <code>null</code> if a lich su xoa an tich with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public LichSuXoaAnTich fetchByPrimaryKey(long lichSuXoaAnTichId)
        throws SystemException {
        return fetchByPrimaryKey((Serializable) lichSuXoaAnTichId);
    }

    /**
     * Returns all the lich su xoa an tichs.
     *
     * @return the lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findAll() throws SystemException {
        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the lich su xoa an tichs.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.LichSuXoaAnTichModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of lich su xoa an tichs
     * @param end the upper bound of the range of lich su xoa an tichs (not inclusive)
     * @return the range of lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findAll(int start, int end)
        throws SystemException {
        return findAll(start, end, null);
    }

    /**
     * Returns an ordered range of all the lich su xoa an tichs.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.LichSuXoaAnTichModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of lich su xoa an tichs
     * @param end the upper bound of the range of lich su xoa an tichs (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<LichSuXoaAnTich> findAll(int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
            finderArgs = FINDER_ARGS_EMPTY;
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
            finderArgs = new Object[] { start, end, orderByComparator };
        }

        List<LichSuXoaAnTich> list = (List<LichSuXoaAnTich>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if (list == null) {
            StringBundler query = null;
            String sql = null;

            if (orderByComparator != null) {
                query = new StringBundler(2 +
                        (orderByComparator.getOrderByFields().length * 3));

                query.append(_SQL_SELECT_LICHSUXOAANTICH);

                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);

                sql = query.toString();
            } else {
                sql = _SQL_SELECT_LICHSUXOAANTICH;

                if (pagination) {
                    sql = sql.concat(LichSuXoaAnTichModelImpl.ORDER_BY_JPQL);
                }
            }

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                if (!pagination) {
                    list = (List<LichSuXoaAnTich>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<LichSuXoaAnTich>(list);
                } else {
                    list = (List<LichSuXoaAnTich>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Removes all the lich su xoa an tichs from the database.
     *
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeAll() throws SystemException {
        for (LichSuXoaAnTich lichSuXoaAnTich : findAll()) {
            remove(lichSuXoaAnTich);
        }
    }

    /**
     * Returns the number of lich su xoa an tichs.
     *
     * @return the number of lich su xoa an tichs
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countAll() throws SystemException {
        Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
                FINDER_ARGS_EMPTY, this);

        if (count == null) {
            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(_SQL_COUNT_LICHSUXOAANTICH);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Initializes the lich su xoa an tich persistence.
     */
    public void afterPropertiesSet() {
        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
                    com.liferay.util.service.ServiceProps.get(
                        "value.object.listener.qldc.pm.tiensu.model.LichSuXoaAnTich")));

        if (listenerClassNames.length > 0) {
            try {
                List<ModelListener<LichSuXoaAnTich>> listenersList = new ArrayList<ModelListener<LichSuXoaAnTich>>();

                for (String listenerClassName : listenerClassNames) {
                    listenersList.add((ModelListener<LichSuXoaAnTich>) InstanceFactory.newInstance(
                            getClassLoader(), listenerClassName));
                }

                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
            } catch (Exception e) {
                _log.error(e);
            }
        }
    }

    public void destroy() {
        EntityCacheUtil.removeCache(LichSuXoaAnTichImpl.class.getName());
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }
}
